<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>stringmatcher_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_labs_testing_stringmatcher_test.js.html">stringmatcher_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.labs.testing.stringMatcherTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.labs.testing.stringMatcherTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.labs.testing.MatcherError&#39;);
<a name="line19"></a>/** @suppress {extraRequire} */
<a name="line20"></a>goog.require(&#39;goog.labs.testing.StringContainsInOrderMatcher&#39;);
<a name="line21"></a>goog.require(&#39;goog.labs.testing.assertThat&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line23"></a>
<a name="line24"></a>function testContainsString() {
<a name="line25"></a>  goog.labs.testing.assertThat(&#39;hello&#39;, containsString(&#39;ell&#39;),
<a name="line26"></a>      &#39;hello contains ell&#39;);
<a name="line27"></a>
<a name="line28"></a>  assertMatcherError(function() {
<a name="line29"></a>    goog.labs.testing.assertThat(&#39;hello&#39;, containsString(&#39;world!&#39;));
<a name="line30"></a>  }, &#39;containsString should throw exception when it fails&#39;);
<a name="line31"></a>}
<a name="line32"></a>
<a name="line33"></a>function testEndsWith() {
<a name="line34"></a>  goog.labs.testing.assertThat(&#39;hello&#39;, endsWith(&#39;llo&#39;), &#39;hello ends with llo&#39;);
<a name="line35"></a>
<a name="line36"></a>  assertMatcherError(function() {
<a name="line37"></a>    goog.labs.testing.assertThat(&#39;minutes&#39;, endsWith(&#39;midnight&#39;));
<a name="line38"></a>  }, &#39;endsWith should throw exception when it fails&#39;);
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>function testEqualToIgnoringWhitespace() {
<a name="line42"></a>  goog.labs.testing.assertThat(&#39;    h\n   EL L\tO&#39;,
<a name="line43"></a>      equalToIgnoringWhitespace(&#39;h el l o&#39;),
<a name="line44"></a>      &#39;&quot;   h   EL L\tO   &quot; is equal to &quot;h el l o&quot;&#39;);
<a name="line45"></a>
<a name="line46"></a>  assertMatcherError(function() {
<a name="line47"></a>    goog.labs.testing.assertThat(&#39;hybrid&#39;, equalToIgnoringWhitespace(&#39;theory&#39;));
<a name="line48"></a>  }, &#39;equalToIgnoringWhitespace should throw exception when it fails&#39;);
<a name="line49"></a>}
<a name="line50"></a>
<a name="line51"></a>function testEquals() {
<a name="line52"></a>  goog.labs.testing.assertThat(&#39;hello&#39;, equals(&#39;hello&#39;),
<a name="line53"></a>      &#39;hello equals hello&#39;);
<a name="line54"></a>
<a name="line55"></a>  assertMatcherError(function() {
<a name="line56"></a>    goog.labs.testing.assertThat(&#39;thousand&#39;, equals(&#39;suns&#39;));
<a name="line57"></a>  }, &#39;equals should throw exception when it fails&#39;);
<a name="line58"></a>}
<a name="line59"></a>
<a name="line60"></a>function testStartsWith() {
<a name="line61"></a>  goog.labs.testing.assertThat(&#39;hello&#39;, startsWith(&#39;hel&#39;),
<a name="line62"></a>      &#39;hello starts with hel&#39;);
<a name="line63"></a>
<a name="line64"></a>  assertMatcherError(function() {
<a name="line65"></a>    goog.labs.testing.assertThat(&#39;linkin&#39;, startsWith(&#39;park&#39;));
<a name="line66"></a>  }, &#39;startsWith should throw exception when it fails&#39;);
<a name="line67"></a>}
<a name="line68"></a>
<a name="line69"></a>function testStringContainsInOrder() {
<a name="line70"></a>  goog.labs.testing.assertThat(&#39;hello&#39;,
<a name="line71"></a>      stringContainsInOrder([&#39;h&#39;, &#39;el&#39;, &#39;el&#39;, &#39;l&#39;, &#39;o&#39;]),
<a name="line72"></a>      &#39;hello contains in order: [h, el, l, o]&#39;);
<a name="line73"></a>
<a name="line74"></a>  assertMatcherError(function() {
<a name="line75"></a>    goog.labs.testing.assertThat(&#39;hybrid&#39;, stringContainsInOrder([&#39;hy&#39;, &#39;brid&#39;,
<a name="line76"></a>      &#39;theory&#39;]));
<a name="line77"></a>  }, &#39;stringContainsInOrder should throw exception when it fails&#39;);
<a name="line78"></a>}
<a name="line79"></a>
<a name="line80"></a>function testMatchesRegex() {
<a name="line81"></a>  goog.labs.testing.assertThat(&#39;foobar&#39;, matchesRegex(/foobar/));
<a name="line82"></a>  goog.labs.testing.assertThat(&#39;foobar&#39;, matchesRegex(/oobar/));
<a name="line83"></a>
<a name="line84"></a>  assertMatcherError(function() {
<a name="line85"></a>    goog.labs.testing.assertThat(&#39;foo&#39;, matchesRegex(/^foobar$/));
<a name="line86"></a>  }, &#39;matchesRegex should throw exception when it fails&#39;);
<a name="line87"></a>}
<a name="line88"></a>
<a name="line89"></a>function assertMatcherError(callable, errorString) {
<a name="line90"></a>  var e = assertThrows(errorString || &#39;callable throws exception&#39;, callable);
<a name="line91"></a>  assertTrue(e instanceof goog.labs.testing.MatcherError);
<a name="line92"></a>}
</pre>


</body>
</html>
